package com.tanhua.server.controller;

import com.tanhua.domain.db.PageResult;
import com.tanhua.domain.vo.TodayBeautyVo;
import com.tanhua.domain.vo.TodayQueryPram;
import com.tanhua.server.service.TodayBeautyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TodayBeautyController {

    @Autowired
    private TodayBeautyService todayBeautyService;

    /**
     * 今日佳人
     *
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity findTodayBeauty() {

        //调用TodayBeautyService方法 返回是TodayBeautyVo
        TodayBeautyVo todayBeautyVo = todayBeautyService.findTodayBeauty();
        //返回
        return ResponseEntity.ok(todayBeautyVo);
    }

    /**
     * 推荐好友
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(TodayQueryPram todayQueryPram) {
        //只获得当前页数 和页尺寸
        Long page = todayQueryPram.getPage();
        Long pagesize = todayQueryPram.getPagesize();
        //调用todayBeautyService 返回PageResult<TodayBeautyVo>
        PageResult<TodayBeautyVo> pageResult = todayBeautyService.recommendation(page, pagesize);
        //返回
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 推荐好友的佳人信息(非缘分值最高)
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity recommendPersonalInfo(@PathVariable("id") Long id) {
        //1.调用service 传入当前id 返回一个TodayBeautyVo对象
        TodayBeautyVo todayBeautyVo = todayBeautyService.recommendPersonalInfo(id);
        //2.返回状态信息
        return ResponseEntity.ok(todayBeautyVo);
    }

    /**
     * 查询陌生人的问题
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity queryStrangerQuestions(Long userId) {
        //1.调用service  传入用户id  返回佳人的问题
        String questionsData = todayBeautyService.strangerQuestions(userId);
        //2.返回状态信息
        return ResponseEntity.ok(questionsData);
    }

    /**
     * 回复陌生人问题
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyStrangerQuestions(@RequestBody Map map) {
        //获取佳人的ID 和陌生人消息
        Integer userId = (Integer) map.get("userId");
        String reply = (String) map.get("reply");
        //1.调用service方法 传入佳人的ID
        todayBeautyService.replyStrangerQuestions(userId, reply);
        //2.返回状态信息
        return ResponseEntity.ok(null);
    }

}
